package com.pro.framework.core;

import cn.hutool.core.util.ReflectUtil;
import com.pro.framework.api.enums.IEnumInt;
import com.pro.framework.api.enums.IEnumStr;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.stream.Collectors;

/**
 * 字典枚举(页面展示可以直接在这枚举里取)
 *
 * @author Administrator
 */
@Slf4j
public class EnumBeanUtil {
    public static void copyProperties(Object source, Object target) {
        Method[] methods = ReflectUtil.getMethods(source.getClass(), m -> m.getName().startsWith("get"));

        for (Method getter : methods) {
            try {
                if (getter.getName().equals("getServiceName")) {
                    int i = 0;
                }
                Object value = getter.invoke(source);
                if (value != null) {
                    String prop = getter.getName().substring(3); // 去掉 "get"
                    String setterName = "set" + prop;
                    Method setter = ReflectUtil.getMethod(target.getClass(), setterName, getter.getReturnType());
                    if (setter != null) {
                        setter.invoke(target, value);
                    }
                }
            } catch (Exception e) {
                // ignore or log
            }
        }
    }
}
